package org.twndmv.bo;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.sun.istack.NotNull;
import com.sun.istack.Nullable;

@Entity
@Table(name="DMV_PERSON")
public class Person {

	@Id @GeneratedValue
	@Column(name="person_id")
	private long id;
	@Column(nullable=false)
	private String firstName;
	private String middleName;
	private String lastName;
	private String nameSuffix;
	
	@OneToOne(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
	@JoinColumn(name="PERSON_CURRRES")
	private Residence currentResidence;
	
	@OneToMany(cascade={CascadeType.ALL})
	@JoinColumn(name="PERSON_RESIDENCE")
	private List<Residence> residences;
	
	@OneToOne(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
	@JoinColumn(name="PERSON_PHYSDETAILS")
	private PhysicalDetails physicalDetails;
	
	@ManyToMany
	@JoinTable(name="VEH_PERSON_OWNERSHIP", joinColumns = {@JoinColumn(name="person_id")},
	inverseJoinColumns = {@JoinColumn(name="vehicle_id")})
	private List<VehicleRegistration> registrations;
    
	public Person() {
		residences = new ArrayList<Residence>();
		setRegistrations(new ArrayList<VehicleRegistration>());
		currentResidence = new Residence();
	}
	
	public Person(long id) {
		setId(id);
		residences = new ArrayList<Residence>();
		currentResidence = new Residence();
	}

	public long getId() {
		return id;
	}

	private void setId(long id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getNameSuffix() {
		return nameSuffix;
	}

	public void setNameSuffix(String nameSuffix) {
		this.nameSuffix = nameSuffix;
	}

	public Residence getCurrentResidence() {
		return currentResidence;
	}

	public void setCurrentResidence(Residence currentResidence) {
		this.currentResidence = currentResidence;
	}

	public List<Residence> getResidences() {
		return residences;
	}

	public void addResidence(Residence newResidence) {
		residences.add(newResidence);
	}

	public PhysicalDetails getPhysicalDetails() {
		return physicalDetails;
	}

	public void setPhysicalDetails(PhysicalDetails physicalDetails) {
		this.physicalDetails = physicalDetails;
	}

	public List<VehicleRegistration> getRegistrations() {
		return registrations;
	}

	public void setRegistrations(List<VehicleRegistration> registrations) {
		this.registrations = registrations;
	}
	
}
